package com.example.limiting.taskmanager2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

/**
 * Created by Limiting on 2015/9/24.
 */
public class WorkerAdapter extends ArrayAdapter<Worker> {
    private Context mContext;
    private int mResourceId;
    public WorkerAdapter(Context context, int textViewResourceId){
        super(context, textViewResourceId);
        this.mContext = context;
        this.mResourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if(null == convertView){
            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(mContext);

            convertView = inflater.inflate(mResourceId, null);
            viewHolder.workerName = (TextView) convertView.findViewById(R.id.worker_name);
            viewHolder.workerContent = (TextView) convertView.findViewById(R.id.worker_content);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Worker worker = getItem(position);

        if(null != worker){
            viewHolder.workerName.setText(worker.getWorkerName());
            viewHolder.workerContent.setText(worker.getWorkerContent());
        }


        return convertView;
    }

    static class ViewHolder{
        TextView workerName;
        TextView workerContent;
    }
}
